package core.config;

/*
 * This class was automatically generated with <a
 * href="http://www.castor.org">Castor 1.3.1</a>, using an XML Schema. $Id$
 */
/**
 * Class EventDescription.
 *
 * @version $Revision$ $Date$
 */
@SuppressWarnings("serial")
public class EventDescription implements java.io.Serializable {

    //--------------------------/
    //- Class/Member Variables -/
    //--------------------------/
    /**
     * Field _name.
     */
    private java.lang.String _name;
    /**
     * Field _eventHandler.
     */
    private java.lang.String _eventHandler;
    /**
     * Field _responseList.
     */
    private java.util.HashMap<String, String> _responseList;

    //----------------/
    //- Constructors -/
    //----------------/
    public EventDescription() {
        super();
        this._responseList = new java.util.HashMap<String, String>();
    }

    //-----------/
    //- Methods -/
    //-----------/
    /**
     *
     *
     * @param vResponse
     * @throws java.lang.IndexOutOfBoundsException if the index given is outside
     * the bounds of the collection
     */
    public void addResponse(final Response vResponse) throws java.lang.IndexOutOfBoundsException {
        this._responseList.put(vResponse.getKey(), vResponse.getValue());
    }

    /**
     *
     *
     * @param index
     * @param vResponse
     * @throws java.lang.IndexOutOfBoundsException if the index given is outside
     * the bounds of the collection
     */
    public void addResponse(final int index, final Response vResponse) throws java.lang.IndexOutOfBoundsException {
        this.addResponse(vResponse);
    }

    /**
     * Method enumerateResponse.
     *
     * @return an Enumeration over all possible elements of this collection
     */
    public java.util.Enumeration<String> enumerateResponse() {
        return java.util.Collections.enumeration(this._responseList.values());
    }

    /**
     * Returns the value of field 'eventHandler'.
     *
     * @return the value of field 'EventHandler'.
     */
    public java.lang.String getEventHandler() {
        return this._eventHandler;
    }

    /**
     * Returns the value of field 'name'.
     *
     * @return the value of field 'Name'.
     */
    public java.lang.String getName() {
        return this._name;
    }

    /**
     * Method getResponse.
     *
     * @param index
     * @throws java.lang.IndexOutOfBoundsException if the index given is outside
     * the bounds of the collection
     * @return the value of the Response at the given index
     */
    public Response getResponse(final String key) throws java.lang.IndexOutOfBoundsException {
//        // check bounds for index
//        if (index < 0 || index >= this._responseList.size()) {
//            throw new IndexOutOfBoundsException("getResponse: Index value '" + index + "' not in range [0.." + (this._responseList.size() - 1) + "]");
//        }
        Response response = new Response();
        response.setKey(key);
        response.setValue(_responseList.get(key));
        return response;
    }

    /**
     * Method getResponse.Returns the contents of the collection in an Array.
     * <p>Note: Just in case the collection contents are changing in another
     * thread, we pass a 0-length Array of the correct type into the API call.
     * This way we <i>know</i> that the Array returned is of exactly the correct
     * length.
     *
     * @return this collection as an Array
     */
    public String[] getResponse() {
        String[] array = new String[0];
        return (String[]) this._responseList.values().toArray(array);
    }

    /**
     * Method getResponseCount.
     *
     * @return the size of this collection
     */
    public int getResponseCount() {
        return this._responseList.size();
    }

    /**
     * Method isValid.
     *
     * @return true if this object is valid according to the schema
     */
    public boolean isValid() {
        try {
            validate();
        } catch (org.exolab.castor.xml.ValidationException vex) {
            return false;
        }
        return true;
    }

    /**
     * Method iterateResponse.
     *
     * @return an Iterator over all possible elements in this collection
     */
    public java.util.Iterator<? extends String> iterateResponse() {
        return this._responseList.values().iterator();
    }

    /**
     *
     *
     * @param out
     * @throws org.exolab.castor.xml.MarshalException if object is null or if
     * any SAXException is thrown during marshaling
     * @throws org.exolab.castor.xml.ValidationException if this object is an
     * invalid instance according to the schema
     */
    public void marshal(
            final java.io.Writer out)
            throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
        org.exolab.castor.xml.Marshaller.marshal(this, out);
    }

    /**
     *
     *
     * @param handler
     * @throws java.io.IOException if an IOException occurs during marshaling
     * @throws org.exolab.castor.xml.ValidationException if this object is an
     * invalid instance according to the schema
     * @throws org.exolab.castor.xml.MarshalException if object is null or if
     * any SAXException is thrown during marshaling
     */
    public void marshal(
            final org.xml.sax.ContentHandler handler)
            throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
        org.exolab.castor.xml.Marshaller.marshal(this, handler);
    }

    /**
     */
    public void removeAllResponse() {
        this._responseList.clear();
    }

    /**
     * Method removeResponse.
     *
     * @param vResponse
     * @return true if the object was removed from the collection.
     */
    public boolean removeResponse(final Response vResponse) {
        boolean removed = _responseList.containsKey(vResponse.getKey());
        _responseList.remove(vResponse.getKey());
        return removed;
    }

    /**
     * Method removeResponseAt.
     *
     * @param index
     * @return the element removed from the collection
     */
    public Response removeResponseAt(
            final int index) {
        java.lang.Object obj = this._responseList.remove(index);
        return (Response) obj;
    }

    /**
     * Sets the value of field 'eventHandler'.
     *
     * @param eventHandler the value of field 'eventHandler'.
     */
    public void setEventHandler(
            final java.lang.String eventHandler) {
        this._eventHandler = eventHandler;
    }

    /**
     * Sets the value of field 'name'.
     *
     * @param name the value of field 'name'.
     */
    public void setName(
            final java.lang.String name) {
        this._name = name;
    }

    /**
     *
     *
     * @param index
     * @param vResponse
     * @throws java.lang.IndexOutOfBoundsException if the index given is outside
     * the bounds of the collection
     */
    public void setResponse(final int index, final Response vResponse) throws java.lang.IndexOutOfBoundsException {
        // check bounds for index
        if (index < 0 || index >= this._responseList.size()) {
            throw new IndexOutOfBoundsException("setResponse: Index value '" + index + "' not in range [0.." + (this._responseList.size() - 1) + "]");
        }

        this._responseList.put(vResponse.getKey(), vResponse.getValue());
    }

    /**
     *
     *
     * @param vResponseArray
     */
    public void setResponse(
            final Response[] vResponseArray) {
        //-- copy array
        _responseList.clear();

        for (int i = 0; i < vResponseArray.length; i++) {
            this._responseList.put(vResponseArray[i].getKey(), vResponseArray[i].getValue());
        }
    }

    /**
     * Method unmarshal.
     *
     * @param reader
     * @throws org.exolab.castor.xml.MarshalException if object is null or if
     * any SAXException is thrown during marshaling
     * @throws org.exolab.castor.xml.ValidationException if this object is an
     * invalid instance according to the schema
     * @return the unmarshaled EventDescription
     */
    public static EventDescription unmarshal(
            final java.io.Reader reader)
            throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
        return (EventDescription) org.exolab.castor.xml.Unmarshaller.unmarshal(EventDescription.class, reader);
    }

    /**
     *
     *
     * @throws org.exolab.castor.xml.ValidationException if this object is an
     * invalid instance according to the schema
     */
    public void validate()
            throws org.exolab.castor.xml.ValidationException {
        org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
        validator.validate(this);
    }
}
